package com.liu.cmsService.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.cmsService.entity.CrmBanner;
import com.liu.cmsService.mapper.CrmBannerMapper;
import com.liu.cmsService.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author LSJ
 * @since 2022-01-17
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {


    @Override
    public void pagesQuery(Page<CrmBanner> bannerPage, String title) {
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
//        1\ 判断查询条件：
        if (ObjectUtils.isEmpty(title)){
            // 查询全部
            baseMapper.selectPage(bannerPage,wrapper);
        }else {

            wrapper.like("title",title);
            baseMapper.selectPage(bannerPage,wrapper);

        }
    }

    @Override
    public List<CrmBanner> getBannerList() {
// 根据id进行降序排序，显示排序后的2条记录
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 2");
        List<CrmBanner> list = baseMapper.selectList(wrapper);
        return  list;


    }
}
